/**
 * output package name
 */
package com.kingdee.eas.mx.imp.ipo.client;

import java.awt.event.*;
import java.util.Date;

import org.apache.log4j.Logger;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.bos.ctrl.kdf.table.IRow;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.query.SQLExecutor;
import com.kingdee.eas.framework.*;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;

/**
 * output class name
 */
public class ContractGTListUI extends AbstractContractGTListUI
{
    private static final Logger logger = CoreUIObject.getLogger(ContractGTListUI.class);
    
    /**
     * output class constructor
     */
    public ContractGTListUI() throws Exception
    {
        super();
    }

	protected ICoreBase getBizInterface() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	protected String getEditUIName() {
		// TODO Auto-generated method stub
		return null;
	}

	protected void btnSelect_actionPerformed(ActionEvent e) throws Exception {
		// TODO Auto-generated method stub
		super.btnSelect_actionPerformed(e);
		Date begintime = (Date)pkBeginTime.getValue();
		Date endtime = (Date)pkEndTime.getValue();
		kDTable1.removeRows();
		//FPurContractNumID
		String sql = "select imp.CFSerial purcontractno,"
			+"sum(scae.FPrice) totalpayment "
			+"from T_IPO_ImpPurContractSelf imp "
			+"left join T_MAS_ImpPurContractNum c "
			+"  on imp.CFSerial = c.fnumber "
			+"left join T_SCO_SingleCAE scae "
			+"on c.fid = scae.FPurContractNumID "
			+"where to_char(imp.FBizdate,'YYYY-MM-DD') between '"+new java.sql.Date(begintime.getTime())+"' "	
			+"and '"+new java.sql.Date(endtime.getTime())+"'    "
			+"group by imp.CFSerial";
		IRowSet irow = new SQLExecutor(sql).executeSQL();
		while(irow.next()){
			IRow row = kDTable1.addRow();
			row.getCell("purcontractno").setValue(irow.getString("purcontractno"));
			if(irow.getString("totalpayment")!=null){
				row.getCell("totalpayment").setValue(irow.getBigDecimal("totalpayment"));
			}else{
				row.getCell("totalpayment").setValue(0);
			}
		}
	}

	protected void btnselectpro_actionPerformed(ActionEvent e) throws Exception {
		// TODO Auto-generated method stub
		super.btnselectpro_actionPerformed(e);
		kDTable1.removeRows();
		//FPurContractNumID
		String sql = "select imp.CFSerial purcontractno,"
			+"sum(scae.FPrice) totalpayment "
			+"from T_IPO_ImpPurContractSelf imp "
			+"left join T_MAS_ImpPurContractNum c "
			+"  on imp.CFSerial = c.fnumber "
			+"left join T_SCO_SingleCAE scae "
			+"on c.fid = scae.FPurContractNumID "
			+"where  imp.cfserial =  '"+ purcontract.getText()+"'     "
			+"group by imp.CFSerial";
		IRowSet irow = new SQLExecutor(sql).executeSQL();
		while(irow.next()){
			IRow row = kDTable1.addRow();
			row.getCell("purcontractno").setValue(irow.getString("purcontractno"));
			if(irow.getString("totalpayment")!=null){
				row.getCell("totalpayment").setValue(irow.getBigDecimal("totalpayment"));
			}else{
				row.getCell("totalpayment").setValue(0);
			}
		}
	}
}